package com.careercup.question.id20960675;

import java.util.ArrayList;
import java.util.Scanner;

public class Solution {
	public static interface Heap<T extends Comparable<T>> {
		public boolean add(T e);
		public T remove();
		public T peek();
		public int size();
	}
	public static class MaxHeap<T extends Comparable<T>> implements Heap<T> {
		ArrayList<T> list;
		public MaxHeap() {
			list = new ArrayList<T>();
		}
		public int size() {
			return list.size();
		}
		public MaxHeap(int initialCapacity) {
			list = new ArrayList<T>(initialCapacity);
		}
		@Override
		public boolean add(T e) {
			list.add(e);
			int c = list.size() - 1, p = (c - 1) / 2;
			while(c > 0 && list.get(p).compareTo(e) < 0) {
				list.set(c, list.get(p));
				c = p;
				p = (c - 1) / 2;
			}
			list.set(c, e);
			return true;
		}

		@Override
		public T remove() {
			if(list.size() <= 0)
				return null;
			if(list.size() == 1)
				return list.remove(0);
			T e = list.remove(list.size() - 1);
			T r = list.set(0, e);
			int p = 0, c = (2 * p + 2 >= list.size() || list.get(2 * p + 1).compareTo(list.get(2 * p + 2)) >= 0) ? 2 * p + 1 : 2 * p + 2;
			while(c < list.size() && list.get(c).compareTo(e) > 0) {
				list.set(p, list.get(c));
				p = c;
				c = (2 * p + 2 >= list.size() || list.get(2 * p + 1).compareTo(list.get(2 * p + 2)) >= 0) ? 2 * p + 1 : 2 * p + 2;
			}
			list.set(p, e);
			return r;
		}
		
		@Override
		public T peek() {
			if(list.size() <= 0)
				return null;
			return list.get(0);
		}
	}
	/**
	 * find K Min Values in an array
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt(), K = in.nextInt();
		Heap<Integer> h = new MaxHeap<Integer>();
		for(int i = 0; i < N; i++) {
			int e = in.nextInt();
			if(h.size() >= K) {
				if(h.peek() >= e) {
					h.remove();
					h.add(e);
				}
			} else
				h.add(e);
		}
		while(h.peek() != null)
			System.out.println(h.remove());
	}
}
